package com.lagou.api;

import org.apache.kudu.client.*;

/*
思路：
1、获取客户端
2、打开一张表
3、创建会话
4、设置刷新模式
5、获取插入实例
6、声明带插入数据
7、刷入数据
8、应用插入实例
9、关闭会话
 */
public class InsertDemo {
    public static void main(String[] args) {
        String masterAddresses = "zb26105";
        KuduClient client = new KuduClient.KuduClientBuilder(masterAddresses).defaultSocketReadTimeoutMs(5000).build();

        try {
            KuduTable stuTable = client.openTable("student");
            KuduSession kuduSession = client.newSession();
            kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);

            Insert insert = stuTable.newInsert();
            insert.getRow().addInt("id",1);
            insert.getRow().addString("name","zlx");

            kuduSession.flush();
            kuduSession.apply(insert);
            kuduSession.close();


        } catch (KuduException e) {
            e.printStackTrace();
        }finally {
            try {
                client.close();
            } catch (KuduException e) {
                e.printStackTrace();
            }
        }
    }
}
